﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.DirectoryServices;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessEntity;
using BusinessLogic;

namespace CentalineWeb
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                var user = Session["user"] == null ? null : Session["user"] as User;
                if (user == null)
                {

                    Response.Redirect("Login.aspx");

                }
                else
                {
                    string username;
                    try
                    {
                        username = user.FullName;
                    }
                    catch (Exception)
                    {
                        username = string.Empty;
                    }

                    var today = DateTime.Today.ToString("yyyy-MM-dd");
                    lblWelcome.Text = string.Format("欢迎您，{0}，[{1}]，{2}", username,new UserRoleManager().GetRoleNameByRoleId(user.RoleId), today);
                    switch (user.RoleId)
                    {
                        case 2:                                //维修人员访问页面权限
                            lbCommitFixReport.Visible = false;
                            lbDept.Visible = false;
                            lbApplyGood.Visible = true;
                            lbSharePrinter.Visible = true;
                            //lblSysmanage.Visible = false;
                            break;
                        case 3:                               //报修人员访问页面权限
                            lbDept.Visible = false;
                            lbApplyGood.Visible = true;
                            lbSharePrinter.Visible = false;
                            //lblSysmanage.Visible = false;
                            break;
                    }
                }
            }
        }



        protected void Page_Init(object sender, EventArgs e)
        {
            if (ConfigurationManager.AppSettings["isLocalTest"] == "true")
            {

                Session["user"] = new UserManager().GetUserById(Convert.ToInt32(ConfigurationManager.AppSettings["testuserid"]));
            }
        }
        /// <summary>
        /// 物品领用链接页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbApplyGood_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://njsps/jsj/Lists/List4/AllItems.aspx");
        }
        /// <summary>
        /// 打印机链接页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbSharePrinter_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://itfast/print/index.html");

        }
    }
}